<?php

/*
 * 1.calcualte sunday array (finshed)
 * 2.set total duties Array (finshed)
 *  notice, validation for duplicate data
 * 3.Via the database, initial staff Array like through each individual staff.
 * 4.calcualte rosterArray
 */

/**
 * Description of roster
 *
 * @author markxi
 */
class roster {

    private $startDate;
    private $endDate;
    private $SundayArray = array();  
    private $dutiesArray = array();
    
    private $staffArray = array();
    // (staff)$Mark,(staff)$Grace        
    // )
    
    private $finalRosterArray = array();
    /*[sunday1]=>Array(
     *              [duty1]=>m1
     *              [duty2]=>m2
     *              [duty3]=>m3
     *              [duty4]=>m4
     *              )
     * 
     */
    
    public function __construct($date1, $date2) {
        if(strtotime($date1)<strtotime($date2)){
        $this->startDate = $date1;
        $this->endDate = $date2;
        $this->caculateSundayArray();
        }  else {
            die("date erro");
        }
    }
    
    
    public function caculateSundayArray(){
        if($this->startDate!=null &  $this->endDate!=null){
            echo 'Sunday is good <br>';//return sundayArray
            $sunday1 = strtotime("next sunday ".$this->startDate);
            while($sunday1<=strtotime($this->endDate)){
                
                //echo date("D-d-M-y",$sunday1)."<br>";
                $this->SundayArray[]=date("Y-m-d",$sunday1);
                //echo $sunday1;
                //echo strtotime($this->endDate);
                $sunday1 +=604800;
            }
            
            
            //$weekNumber =(int)((strtotime('next sunday',$this->endDate)-strtotime('last sunday',$this->startDate))/604800);
            //echo $weekNumber;
            
            
            
        }else{
            echo 'please initiate start and end date';
        }
        
    }
    
    public function ShowSundayArray(){
        //return $this->SundayArray;
        echo'<pre>';
        print_r($this->SundayArray);
    }
    
    public function getSundaysArray(){
        return $this->SundayArray;
    }
    
    public function setDuitesArray($DutyArray){
        $this->dutiesArray =$DutyArray;
    }
    public function getDutyArray(){
        return $this->dutiesArray;
    }
    public function showDutyArray(){
        echo '<pre>';
        print_r($this->dutiesArray);
    }
    
    public function updateArray(){}
    public function deleteArray(){}
    
    public function addDutyInArray($newDuty){
        $this->dutiesArray[]= $newDuty;
    }
    public function updateDutyArray($oldDuty,$newDuty){
        foreach ($this->dutiesArray as $key => $value) {
            if($value == $oldDuty){
                $this->dutiesArray[$key] = $newDuty;
            }
        }
        return 1;
    }
    
    
    
}

?>
